package com.Iconcat.system.mapper;

import com.Iconcat.system.entity.Investment;
import com.Iconcat.system.entity.WithdrawalRecord;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zzq
 * @since 2023-12-19
 */
public interface InvestmentMapper extends BaseMapper<Investment> {
    @Update("UPDATE investment SET investment_status=#{investment_status} WHERE user_id = #{userId} and project_id=#{projectId}")
    void updateStatusToWithdrawn(@Param("userId")Integer userId,@Param("projectId") Integer projectId,@Param("status") String status);
    Integer  hasInvested(@Param("userId") Integer userId, @Param("projectId") Integer projectId);
    @Select("SELECT project_earnings FROM investment where user_id = #{userId} and project_id=#{projectId}")
    BigDecimal SelectProjectEarnings(@Param("userId")Integer userId, @Param("projectId") Integer projectId);
    @Select("SELECT i.investment_id, i.user_id, u.user_name, u.phone_number, " +
            "i.project_id, p.project_name, i.investment_amount, i.investment_time, " +
            "i.investment_status, i.project_earnings " +
            "FROM investment i " +
            "JOIN cat_user u ON i.user_id = u.userid " +
            "JOIN cat_project p ON i.project_id = p.project_id " +
            "${ew.customSqlSegment}" )
    IPage<Map<String, Object>> selectProjectInvestment(Page<?> page,@Param(Constants.WRAPPER) LambdaQueryWrapper<Investment> ew);

}
